package spring.boot.btc.utils;

import io.github.novacrypto.base58.Base58;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;

/**
 * base64工具
 *
 * @author blues
 */
public final class BaseUtils {


    public static String toBase64(String before) {
        return new Base64().encodeAsString(before.getBytes());
    }

    public static String toBase64(byte[] before) {
        return new Base64().encodeAsString(before);
    }

    public static String fromBase64ToString(String base64) {
        return StringUtils.newStringUtf8(new Base64().decode(base64));
    }

    public static byte[] fromBase64ToByte(String base64) {
        return new Base64().decode(base64);
    }


    public static String toBase58(String before) {
        return Base58.base58Encode(before.getBytes());
    }

    public static String toBase58(byte[] before) {
        return Base58.base58Encode(before);
    }

    public static String fromBase58ToString(String base58) {
        return StringUtils.newStringUtf8(Base58.base58Decode(base58));
    }

    public static byte[] fromBase58ToByte(String base58) {
        return Base58.base58Decode(base58);
    }
}
